package com.qcby.util;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author haozeWang
 * @create 2021-08-23 15:13
 */

public class SysEcxceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        SysException exception=null;
        /*判断是否为自建异常对象*/
        if(e instanceof SysException){
            exception=(SysException)e;
        }else{
            exception=new SysException("系统出错");
        }
        ModelAndView mv=new ModelAndView();
        /*设置数据与视图*/
        mv.setViewName("404");
        mv.addObject("error",exception.getMessage() );
        return mv;
    }
}
